package com.nage.components.collision;

import com.nage.components.Component;
import com.nage.components.display.Shape;
import com.nage.components.movement.Physics;
import com.nage.engine.GameObject;

public class CollisionMask extends Component {
	
	/**
	 * Used for determining collisions. This is just a rectangular mask.
	 */
	float left, right, top, bottom;
	
	/**
	 * previous values for each.
	 */
	float pLeft, pRight, pTop, pBottom;
	
	/**
	 * This CollisionMask simply follows around a shape
	 */
	Shape shape;

	public CollisionMask(GameObject p) {
		super(p);
		type = COLLISION_MASK;
	}

	@Override
	public boolean findLinks() {
		shape = (Shape) parent.getComponent(SHAPE);
		if(shape==null) {
			return false;
		} 
		left = shape.x;
		top = shape.y;
		right = left + shape.width;
		bottom = top - shape.height;
		return true;
	}

	@Override
	public void update(long delta) {
		pLeft = left;
		pRight = right;
		pTop = top;
		pBottom = bottom;
		left = shape.x;
		bottom = shape.y;
		right = left + shape.width;
		top = bottom + shape.height;
	}
	
	/**
	 * Checks to see if a point is within the bounds of the mask
	 * 
	 * @param x		x coordinate of point
	 * @param y		y coordinate of point
	 * @return		true | false depending on position
	 */
	public boolean isInside(float x, float y) {
		return (x > left && x < right && y > bottom & y < top);
	}

}
